package com.miage.kangourou.client.calendar;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class CalendarMouseEvent extends GenericWidget{

	private HorizontalPanel menuPanel = new HorizontalPanel();
	private Label title = new Label();
	private Button previousWeek = new Button(" << ");
	private Button nextWeek = new Button(" >> ");
	private Button today = new Button("Aujourd'hui");
	private Hyperlink connection = new Hyperlink("connexion", false, "");
	
	public CalendarMouseEvent(KangourouPanel context) {
		super(context, "menu");
	}
	
	public Widget createWidget() {
		menuPanel = new HorizontalPanel();
		title = new Label();
		previousWeek = new Button(" << ");
		nextWeek = new Button(" >> ");
		today = new Button("Aujourd'hui");
		connection = new Hyperlink("connexion", false, "");
		
		menuPanel.add(previousWeek);		
		menuPanel.add(today);
		menuPanel.add(nextWeek);
		menuPanel.add(title);
		menuPanel.add(connection);
		menuPanel.setCellHorizontalAlignment(title, HasHorizontalAlignment.ALIGN_CENTER);
		menuPanel.setCellVerticalAlignment(title, HasVerticalAlignment.ALIGN_MIDDLE);
		menuPanel.setCellWidth(previousWeek, "1%");
		menuPanel.setCellWidth(nextWeek, "1%");
		menuPanel.setCellWidth(today, "1%");
		menuPanel.setCellWidth(connection, "1%");
		menuPanel.setCellWidth(title, "100%");
		menuPanel.setWidth("100%");
		
		return menuPanel;
	}

	
	public void configureWidget() {
		menuPanel.setWidth("100%");
		
		connection.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {		
				PopUpConnection popUpConnection = new PopUpConnection();
				popUpConnection.CreatePopUpConnection(context).show();
			}
		});
	
		previousWeek.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				context.clickChangeDateButton(-7);
			}
		});
	
		nextWeek.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				context.clickChangeDateButton(7);
			}
		});
	
		today.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				context.clickChangeDateButton(-1);
			}
		});
	}
	
	
	public Label getTitle() {
		return title;
	}

	public Button getPreviousWeek() {
		return previousWeek;
	}

	public Button getNextWeek() {
		return nextWeek;
	}

	public Button getToday() {
		return today;
	}

	public Hyperlink getConnection() {
		return connection;
	}

	
}
